package com.corgi.multi.anno.controller;

import com.corgi.multi.anno.domain.A;
import com.corgi.multi.anno.domain.UserLogin;
import com.corgi.multi.anno.service.AService;
import com.corgi.multi.anno.service.DataSourceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * DataSourceController
 *
 * @title: DataSourceController
 * @description:
 * @author: dengmiao
 * @create: 2020-05-21 19:45
 **/
@RestController
@Slf4j
public class DataSourceController {

    @Autowired
    private DataSourceService dataSourceService;

    @Autowired
    private AService aService;

    @GetMapping("/default/{id}")
    public List<UserLogin> useDefaultDataSource(@PathVariable("id") Long id) {
        log.info("使用默认数据源");
        List<UserLogin> list = dataSourceService.selectById(id);
        return list;
    }

    @GetMapping("/ds1")
    public List<UserLogin> useDS1DataSource() {
        log.info("使用ds1数据源");
        List<UserLogin> list = dataSourceService.selectAllDs1();
        return list;
    }

    @GetMapping("/ds2")
    public List<UserLogin> useDS2DataSource() {
        log.info("使用ds2数据源");
        List<UserLogin> list = dataSourceService.selectAllDs2();
        return list;
    }

    @GetMapping("sqlServer")
    public List<A> get() {
        return aService.findAll();
    }
}
